package com.tqsa.web.controller;

import cn.hutool.core.bean.BeanUtil;
import com.tqsa.common.convention.result.Result;
import com.tqsa.dto.UserRegisterDTO;
import com.tqsa.dto.UserUpdateDTO;
import com.tqsa.vo.UserVO;
import com.tqsa.web.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @author zhangjiaqing
 * @version 1.0
 * @date 2024/3/25 15:00
 * @description: TODO
 */
@Api(tags = "示例:用户接口")
@RestController
@RequestMapping("/api/data-evaluation/v1/user")
@RequiredArgsConstructor
public class UserController {

    private final UserService userService;

    @ApiOperation (value = "根据用户名获取用户信息")
    @GetMapping("/{username}")
    public Result<UserVO> getUserByUsername (@PathVariable String username){
        return userService.getUserByUserName(username);
    }

    @ApiOperation (value = "用户注册")
    @PostMapping ("/save")
    public Result<Void> register (@RequestBody UserRegisterDTO userRegisterDTO){
        return userService.register(userRegisterDTO);
    }

    @ApiOperation (value = "根据用户名删除用户信息")
    @DeleteMapping("/{username}")
    public Result<Void> deleteUserByUsername (@PathVariable String username){
        return userService.deleteUserByUsername(username);
    }

    @ApiOperation (value = "根据用户名修改用户信息")
    @PutMapping("/update")
    public Result<Void> updateUserByUsername (@RequestBody UserUpdateDTO userUpdateDTO){
        return userService.updateUserByUsername(userUpdateDTO);
    }

}
